/**
 * TraditionalServer.java created by zhangzhidong 
 * at 下午8:56:45 2016年9月3日
 */
package nio;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author zhangzhidong<br>
 * comment generated at 2016年9月3日下午8:56:45<br>
 * 
 */
public class TraditionalServer {

	/**
	 * 下午8:56:46 2016年9月3日
	 * @param args
	 */
	public static void main(String[] args) {
		Executor tp = Executors.newFixedThreadPool(10);
		ServerSocket echoServer = null;
        Socket clientSocket = null;
        try {
            echoServer = new ServerSocket(8000);
        } catch (IOException e) {
            System.out.println(e);
        }
        while (true) {
            try {
                clientSocket = echoServer.accept();
                System.out.println(clientSocket.getRemoteSocketAddress()
                        + " connect!");
                //tp.execute(new HandleMsg(clientSocket));
            } catch (IOException e) {
                System.out.println(e);
            }
        }
		

	}
	static class HandleMsg implements Runnable{  
		BufferedReader is = null;
		
        public void run(){         
            try {         
                //is = new BufferedReader(/*new InputStreamReader(clientSocket.getInputStream())*/); 
                //os = new PrintWriter(clientSocket.getOutputStream(), true); 
                // 从InputStream当中读取客户端所发送的数据              
                String inputLine = null;                 
                long b=System. currentTimeMillis ();                 
                while ((inputLine = is.readLine()) != null)
                {           
                 //   os.println(inputLine);                 
                }                 
                long e=System. currentTimeMillis ();                 
                System. out.println ("spend:"+(e - b)+" ms ");             
           } catch (IOException e) {                 
               e.printStackTrace();             
           }finally
           {  
               //关闭资源 
           }     
       } 
    }

}
